<html>
    <head>test</head>
    <body>
        account: <span id='account'></span><br>
        land fee: <span id='text-land-com'></span><br>
        wait: <span id='wait'></span>
        <div id='log'></div>
    </body>
    <script src="https://gitee.com/baby4/awhtml/raw/master/js/waxjs.js" type="text/javascript"></script>
    <script src="https://gitee.com/baby4/awhtml/raw/master/js/bundleNew.js" type="text/javascript"></script>
    <script src="https://gitee.com/baby4/awhtml/raw/master/js/login.js"></script>
    <script src="https://gitee.com/baby4/awhtml/raw/master/js/mindelay.js"></script>
    <script src="https://gitee.com/baby4/awhtml/raw/master/js/mine.js"></script>
    <script type="text/javascript">
        class Log{
            constructor(){
                this.arr = new Array(10);
                this.pointer = 0;
                this.length = 0;
            }

            log(s){
                this.arr[this.pointer] = s;
                this.length += 1;
                this.show();
                this.pointer = (this.pointer+1)%10;
            }

            show(){
                let view = "";
                if(this.length<10||this.pointer==9){
                    for(var i=0;i<=this.pointer;i++){
                        view += `${this.arr[i]}<br>`;
                    }
                }else{
                    for(var i=this.pointer+1;i<10;i++){
                        view += `${this.arr[i]}<br>`;
                    }
                    for(var i=0;i<=this.pointer;i++){
                        view += `${this.arr[i]}<br>`;
                    }
                }
                document.getElementById("log").innerHTML = view;
            }
        }

        function sleep(ms) {
            return new Promise(resolve => setTimeout(resolve, ms))
        }

        class CountingDown{
            constructor(){
                this.countingInterval = null;
            }

            async wait(delay){
                if(delay<=0){
                    document.getElementById("wait").innerHTML = `go to mine`;
                    return;
                }
                this.countingInterval = setInterval(function(){
                    delay -= 1000;
                    if(delay>500){
                        document.getElementById("wait").innerHTML = `${Math.ceil(delay/1000)} sec`;
                    }else{
                        document.getElementById("wait").innerHTML = `go to mine`;
                        clearInterval(this.countingInterval);
                    }
                }, 1000);
                await sleep(delay);
            }
        }
        const logging = new Log();
        const count= new CountingDown();

        async function main(){
            let loginTimeout = setInterval(function(){location.reload()}, 300000);
            await serverLogin();
            clearInterval(loginTimeout);

            const minedelay = await getMineDelay(wax.userAccount);
            await count.wait(minedelay);
            while(true){
                let failCount = await mine(logging);
                if(failCount>=10) location.reload();
                await count.wait(405000);
            }
        }
        main();
    </script>
</html>